package org.FaPe3D.core.parsers
{
	import flash.utils.Dictionary;
	
	import org.FaPe3D.core.parsers.casting.*;
	
	public class Setting
	{
		
		public function Setting()
		{
		}
		
		public static function parse(xml:XML):Dictionary
		{
			var dic:Dictionary = new Dictionary();
			
			// path
			var arrPath:Array = new Array();
			for(var path:uint = 0; path< xml.fape3d.path.item.length(); path++)
			{
				arrPath.push({
								(''+xml.fape3d.path.item[path].@id) :  (xml.fape3d.path.item[path]).toString()
							});
				//
				dic['path.' + xml.fape3d.path.item[path].@id] = (xml.fape3d.path.item[path]).toString();
			}
			dic['path'] = arrPath;
			
			
			// propertys
			var arrPropertys:Array = new Array();
			for(var property:uint = 0; property< xml.fape3d.property.children().length(); property++)
			{
				arrPropertys.push({
									(''+xml.fape3d.property.children()[property].name()) : Common.cast(xml.fape3d.property.children()[property].@type, xml.fape3d.property.children()[property].text())
								  });
				//
				dic['property.' + xml.fape3d.property.children()[property].name()] = Common.cast(xml.fape3d.property.children()[property].@type, xml.fape3d.property.children()[property].text());
			}
			dic['property'] = arrPropertys;
			
			// languages
			var arrLanguages:Array = new Array();
			var objLanguages:Object = new Object();
			for(var languages:uint = 0; languages< xml.fape3d.languages.item.length(); languages++)
			{
				objLanguages = {
			 	 	'name'      : xml.fape3d.languages.item[languages].text()          ,
			 	 	'direction' : xml.fape3d.languages.item[languages].@direction      ,
			 	 	'default'   : (xml.fape3d.languages.item[languages].@default == undefined) ? false : true
							 	};
				
				arrLanguages.push(objLanguages);
				dic['languages.' + xml.fape3d.languages.item[languages].text()] = objLanguages;
			}
			dic['languages'] = arrLanguages;
			
			// allowdomains
			var arrAllowdomains:Array = new Array();
			for(var allowdomains:uint = 0; allowdomains< xml.fape3d.allowdomains.item.length(); allowdomains++)
			{
				arrAllowdomains.push(xml.fape3d.allowdomains.item[allowdomains].text());
			}
			dic['allowdomains'] = arrAllowdomains;
			
			
			// custom
			var arrCustom:Array = new Array();
			for(var custom:uint = 0; custom< xml.custom.children().length(); custom++)
			{
				arrCustom.push({
								(''+ xml.custom.children()[custom].name())  : Common.cast(xml.custom.children()[custom].@type, xml.custom.children()[custom].text())
								});
				//
				dic['custom.' + xml.custom.children()[custom].name()] = Common.cast(xml.custom.children()[custom].@type, xml.custom.children()[custom].text());
			}
			dic['custom'] = arrCustom;	
			
			return dic;
		}
		
	}
}